package com.mba.activity;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.TabHost;
import android.widget.RadioGroup.OnCheckedChangeListener;

/**
 * Jeffrey Shey
 * Mail shijunfan@163.com
 * QQ 362116120
 * blog http://opdar.com
 */
public class OtherMsgTabActivity extends TabActivity implements OnCheckedChangeListener{
	private RadioGroup mainTab;
	private TabHost mTabHost;
	
	//内容Intent
	private Intent mHomeIntent;
	private Intent mMsgIntent;
	private Intent mSettingIntent;
	
	private final static String TAB_TAG_HOME="tab_tag_home";
	private final static String TAB_TAG_MSG="tab_tag_msg";
	private final static String TAB_TAG_SETTING="tab_tag_setting";

    @Override
    public void onCreate(Bundle savedInstanceState) {
    
    	 super.onCreate(savedInstanceState);
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         setContentView(R.layout.main);
         mainTab=(RadioGroup)findViewById(R.id.main_tab);
         mainTab.setOnCheckedChangeListener(this);
         prepareIntent();
         setupIntent();
       
    }
    
    
    /**
     * 准备tab的内容Intent
     */
	private void prepareIntent() {
		
		mHomeIntent=new Intent(this, HomeActivity.class);
		mMsgIntent=new Intent(this, MsgActivity.class);
		mSettingIntent=new Intent(this, SettingActivity.class);
	}
	
	/**
	 * 
	 */
	private void setupIntent() {
		this.mTabHost=getTabHost();
		TabHost localTabHost=this.mTabHost;
		localTabHost.addTab(buildTabSpec(TAB_TAG_HOME, R.string.main_news, R.drawable.icon_1_n, mHomeIntent));
		localTabHost.addTab(buildTabSpec(TAB_TAG_MSG, R.string.menu_msg, R.drawable.icon_2_n, mMsgIntent));
		localTabHost.addTab(buildTabSpec(TAB_TAG_SETTING, R.string.menu_setting, R.drawable.icon_3_n, mSettingIntent));
	}
	/**
	 * 构建TabHost的Tab页
	 * @param tag 标记
	 * @param resLabel 标签
	 * @param resIcon 图标
	 * @param content 该tab展示的内容
	 * @return 一个tab
	 */
	private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon,final Intent content) {
		return this.mTabHost.newTabSpec(tag).setIndicator(getString(resLabel),
				getResources().getDrawable(resIcon)).setContent(content);
	} 
	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		switch(checkedId){
		case R.id.radio_button0:
			this.mTabHost.setCurrentTabByTag(TAB_TAG_HOME);
			break;
		case R.id.radio_button1:
			this.mTabHost.setCurrentTabByTag(TAB_TAG_MSG);
			break;
		case R.id.radio_button2:
			this.mTabHost.setCurrentTabByTag(TAB_TAG_SETTING);
			break;
		}
	}
}
